<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    let print1 = function (obj) {
        console.log(obj)
    }
    print1('abc')
    //箭头函数
    let print2 = obj => console.log(obj)
    print2('456')

    let sum1 = function (a, b) {
        return a + b
    }
    //return可以省略
    let sum2 = (a, b) => a + b
    console.log(sum2(3, 5))

    let person = {
        name: 'zhansgan',
        //以前
        eat1: function (food) {
            console.log(this.name + '在吃：' + food)
        },
        //箭头函数方式
        eat2: food => console.log(person.name + '在吃：' + food),
        eat3(food) {
            console.log(this.name + '在吃：' + food)
        }
    }
    person.eat1('苹果')
    person.eat2('香蕉')
    person.eat3('草莓')

    let arr = ['1','20','-5','3'];
    console.log(arr)
    /*arr = arr.map(function (s) {
        return parseInt(s)
    })
    console.log(arr)*/
    arr = arr.map(s => parseInt(s))
    console.log(arr)

    let arr1 = [1,20,-5,3];
    let result1 = arr1.reduce(function (a, b) {
        //1 20
        //21 -5
        //16 3
        console.log(a, b)
        return a + b
    })
    console.log(result1)
    let result2 = arr1.reduce((a, b) => a + b)
    console.log(result2)
    let result3 = arr1.reduce((a, b) => a * b)
    console.log(result3)
    let result4 = arr1.reduce(function (a, b) {
        //0 1
        //0 20
        //0 -5
        console.log(a, b)
        return a * b
    }, 0)
    console.log(result4)
    let result5 = arr1.reduce((a, b) => a + b, 0)
</script>
</body>
</html>